import { ref } from 'vue'

let categoryIdSeed = 100
export function getNextCategoryId() {
    return ++categoryIdSeed
}

export const categoriesTree = ref([
    { id: 1, name: '商品推广', icon: '', children: [] },
    {
        id: 2, name: '活动促销', icon: '', children: [
            { id: 21, name: '618大促', icon: '', children: [] },
            { id: 22, name: '双11', icon: '', children: [] }
        ]
    },
    { id: 3, name: '品牌故事', icon: '', children: [] },
    { id: 4, name: '用户评价', icon: '', children: [] },
    { id: 5, name: '其他', icon: '', children: [] }
])

export const list = ref([
    { id: 1, title: '618大促文案', content: '全场满200减30，爆款直降，限时抢购！', category: 1, updatedAt: '2024-06-01 10:00', icon: '', weight: 1, mainImage: '', thumbImage: '', readCount: 123, status: 'published' },
    { id: 2, title: '品牌故事文案', content: '源自日本，专注品质生活。', category: 3, updatedAt: '2024-05-28 15:20', icon: '', weight: 2, mainImage: '', thumbImage: '', readCount: 88, status: 'draft' },
    { id: 3, title: '用户好评文案', content: '收到商品很满意，物流很快，推荐！', category: 4, updatedAt: '2024-05-20 09:30', icon: '', weight: 3, mainImage: '', thumbImage: '', readCount: 56, status: 'published' }
])

export function getCategoryNameById(id: number, tree: any[]): string {
    for (const node of tree) {
        if (node.id === id) return node.name
        if (node.children && node.children.length) {
            const found = getCategoryNameById(id, node.children)
            if (found) return found
        }
    }
    return ''
} 